home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / OS / FWEvents / Sources / FWEvent.cpp next >
Encoding:
Text File  |  1995-11-08  |  35.1 KB  |  1,043 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:        FWEvent.cpp
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Copyright:    1995 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWOS.hpp"
  11.  
  12. #ifndef FWEVENT_H
  13. #include "FWEvent.h"
  14. #endif
  15.  
  16. #ifndef FWMEMMGR_H
  17. #include "FWMemMgr.h"
  18. #endif
  19.  
  20. #ifndef FWPOINT_H
  21. #include "FWPoint.h"
  22. #endif
  23.  
  24. #ifndef FWMAPING_H
  25. #include "FWMaping.h"
  26. #endif
  27.  
  28. #ifndef FWFCTINF_H
  29. #include "FWFctInf.h"
  30. #endif
  31.  
  32. #ifndef FWACQUIR_H
  33. #include "FWAcquir.h"
  34. #endif
  35.  
  36. // ----- OpenDoc Includes -----
  37. #ifndef SOM_ODWindow_xh
  38. #include <Window.xh>
  39. #endif
  40.  
  41. #ifndef SOM_ODFacet_xh
  42. #include <Facet.xh>
  43. #endif
  44.  
  45. #ifndef SOM_ODFrame_xh
  46. #include <Frame.xh>
  47. #endif
  48.  
  49. #ifndef SOM_ODTransform_xh
  50. #include <Trnsform.xh>
  51. #endif
  52.  
  53. // ----- Macintosh Includes -----
  54.  
  55. #if defined(FW_BUILD_MAC) && !defined(__DRAG__)
  56. #include <Drag.h>
  57. #endif
  58.  
  59. #if FW_LIB_EXPORT_PRAGMAS
  60. #pragma lib_export on
  61. #endif
  62.  
  63. //========================================================================================
  64. //    RunTime Info
  65. //========================================================================================
  66.  
  67. #pragma segment fwevents
  68.  
  69. FW_DEFINE_CLASS_M0(FW_CSystemEvent)
  70. FW_DEFINE_CLASS_M1(FW_CNullEvent, FW_CSystemEvent)
  71. FW_DEFINE_CLASS_M1(FW_CMouseEvent, FW_CSystemEvent)
  72. FW_DEFINE_CLASS_M1(FW_CEmbeddedMouseEvent, FW_CMouseEvent)
  73. FW_DEFINE_CLASS_M1(FW_CBorderMouseEvent, FW_CMouseEvent)
  74. FW_DEFINE_CLASS_M1(FW_CVirtualKeyEvent, FW_CSystemEvent)
  75. FW_DEFINE_CLASS_M1(FW_CCharKeyEvent, FW_CSystemEvent)
  76. FW_DEFINE_CLASS_M1(FW_CActivateEvent, FW_CSystemEvent)
  77. FW_DEFINE_CLASS_M1(FW_CSuspendResumeEvent, FW_CSystemEvent)
  78. FW_DEFINE_CLASS_M1(FW_CMenuEvent, FW_CSystemEvent)
  79. #ifdef FW_BUILD_MAC
  80. FW_DEFINE_CLASS_M1(FW_CMacWindowEvent, FW_CSystemEvent)
  81. #endif
  82.  
  83. //========================================================================================
  84. //    Constants
  85. //========================================================================================
  86.  
  87. const short FW_CMouseEvent::kEmpty = 0;
  88. const short FW_CMouseEvent::kExtend = 1;
  89. const short FW_CMouseEvent::kItem = 2;
  90. const short FW_CMouseEvent::kCopy = 4;
  91. const short FW_CMouseEvent::kControl = 8;
  92.  
  93. //========================================================================================
  94. // CLASS FW_CSystemEvent
  95. //========================================================================================
  96.  
  97. //----------------------------------------------------------------------------------------
  98. //    FW_CSystemEvent::FW_CSystemEvent
  99. //----------------------------------------------------------------------------------------
  100. FW_CSystemEvent::FW_CSystemEvent(Environment* ev, ODPlatformWindow theWindow, FW_PlatformEventTime time)
  101. {
  102. #ifdef FW_BUILD_MAC
  103.     FW_CMemoryManager::SetMemory(&fEvent, sizeof(ODEventData), 0);
  104.     fEvent.when = time;
  105.     fPlatformWindow = theWindow;
  106. #endif
  107. #ifdef FW_BUILD_WIN
  108.     FW_CMemoryManager::SetMemory(&fEvent, sizeof(MSG), 0);
  109.     FW_ASSERT(theWindow != NULL);
  110.     fEvent.hwnd = theWindow;
  111.     fEvent.time = time;
  112.     fPlatformWindow = theWindow;
  113. #endif
  114. }
  115.  
  116. //----------------------------------------------------------------------------------------
  117. //    FW_CSystemEvent::FW_CSystemEvent
  118. //----------------------------------------------------------------------------------------
  119. FW_CSystemEvent::FW_CSystemEvent(Environment* ev, ODEventData* theEvent)
  120. {
  121. #ifdef FW_BUILD_MAC
  122.     FW_CMemoryManager::CopyMemory(theEvent, &fEvent, sizeof(ODEventData));
  123.     fPlatformWindow = NULL;
  124. #endif
  125.  
  126. #ifdef FW_BUILD_WIN
  127.     FW_CMemoryManager::CopyMemory(theEvent, &fEvent, sizeof(MSG));
  128.     fPlatformWindow = (HWND)fEvent.hwnd;
  129. #endif
  130. }
  131.  
  132. //----------------------------------------------------------------------------------------
  133. //    FW_CSystemEvent::FW_CSystemEvent
  134. //----------------------------------------------------------------------------------------
  135. FW_CSystemEvent::FW_CSystemEvent(Environment* ev, const FW_CSystemEvent& other)
  136. {
  137. #ifdef FW_BUILD_MAC
  138.     FW_CMemoryManager::CopyMemory(((FW_CSystemEvent&)other).GetPlatformEvent(), &fEvent, sizeof(ODEventData));
  139. #endif
  140.  
  141. #ifdef FW_BUILD_WIN
  142.     FW_CMemoryManager::CopyMemory(((FW_CSystemEvent&)other).GetPlatformEvent(), &fEvent, sizeof(MSG));
  143. #endif
  144.  
  145.     fPlatformWindow = other.GetPlatformWindow();
  146. }
  147.  
  148. //----------------------------------------------------------------------------------------
  149. //    FW_CSystemEvent::~FW_CSystemEvent
  150. //----------------------------------------------------------------------------------------
  151. FW_CSystemEvent::~FW_CSystemEvent()
  152. {
  153. }
  154.  
  155. //========================================================================================
  156. // CLASS FW_CNullEvent
  157. //========================================================================================
  158.  
  159. //----------------------------------------------------------------------------------------
  160. //    FW_CNullEvent::FW_CNullEvent
  161. //----------------------------------------------------------------------------------------
  162. FW_CNullEvent::FW_CNullEvent(Environment* ev, ODEventData* theEvent) :
  163.     FW_CSystemEvent(ev, theEvent)
  164. {
  165. }
  166.  
  167. //----------------------------------------------------------------------------------------
  168. //    FW_CNullEvent::FW_CNullEvent
  169. //----------------------------------------------------------------------------------------
  170. FW_CNullEvent::FW_CNullEvent(Environment* ev, ODPlatformWindow theWindow, FW_PlatformEventTime time) :
  171.     FW_CSystemEvent(ev, theWindow, time)
  172. {
  173. }
  174.  
  175. //----------------------------------------------------------------------------------------
  176. //    FW_CNullEvent::FW_CNullEvent
  177. //----------------------------------------------------------------------------------------
  178. FW_CNullEvent::FW_CNullEvent(Environment* ev, const FW_CNullEvent& other) :
  179.     FW_CSystemEvent(ev, other)
  180. {
  181. #ifdef FW_BUILD_MAC
  182.     fEvent.what = nullEvent;
  183. #endif
  184. #ifdef FW_BUILD_WIN
  185.     fEvent.message = WM_NULL;
  186. #endif
  187. }
  188.  
  189. //----------------------------------------------------------------------------------------
  190. //    FW_CNullEvent::~FW_CNullEvent
  191. //----------------------------------------------------------------------------------------
  192. FW_CNullEvent::~FW_CNullEvent()
  193. {
  194. }
  195.  
  196. //========================================================================================
  197. // CLASS FW_CMacWindowEvent
  198. //========================================================================================
  199.  
  200. #ifdef FW_BUILD_MAC
  201. //----------------------------------------------------------------------------------------
  202. //    FW_CMacWindowEvent::FW_CMacWindowEvent
  203. //----------------------------------------------------------------------------------------
  204. FW_CMacWindowEvent::FW_CMacWindowEvent(Environment* ev, ODEventData* theEvent) :
  205.     FW_CSystemEvent(ev, theEvent)
  206. {
  207. }
  208. #endif
  209.  
  210. #ifdef FW_BUILD_MAC
  211. //----------------------------------------------------------------------------------------
  212. //    FW_CMacWindowEvent::~FW_CMacWindowEvent
  213. //----------------------------------------------------------------------------------------
  214. FW_CMacWindowEvent::~FW_CMacWindowEvent()
  215. {
  216. }
  217. #endif
  218.  
  219. //========================================================================================
  220. // CLASS FW_CMouseEvent
  221. //========================================================================================
  222.  
  223. //----------------------------------------------------------------------------------------
  224. //    FW_CMouseEvent::FW_CMouseEvent
  225. //----------------------------------------------------------------------------------------
  226. FW_CMouseEvent::FW_CMouseEvent(Environment* ev, ODEventData* theEvent, ODFacet* theFacet, ButtonState theState, short numOfClicks) :
  227.     FW_CSystemEvent(ev, theEvent),
  228.     fFacet(theFacet),
  229.     fButtonState(theState),
  230.     fNumberOfClicks(numOfClicks)
  231. {
  232. #ifdef FW_BUILD_MAC
  233.     fWhichButton = kLeftMouseButton;
  234. #endif
  235. #ifdef FW_BUILD_WIN
  236.     if (theEvent->message == WM_LBUTTONDOWN || theEvent->message == WM_LBUTTONUP)
  237.         fWhichButton = kLeftMouseButton;
  238.     else if (theEvent->message == WM_MBUTTONDOWN || theEvent->message == WM_RBUTTONUP)
  239.         fWhichButton = kMiddleMouseButton;
  240.     else
  241.         fWhichButton = kRightMouseButton;
  242. #endif
  243. }
  244.  
  245. //----------------------------------------------------------------------------------------
  246. //    FW_CMouseEvent::FW_CMouseEvent
  247. //----------------------------------------------------------------------------------------
  248. FW_CMouseEvent::FW_CMouseEvent(Environment* ev, 
  249.                             ODFacet* theFacet,
  250.                             ButtonState theState,
  251.                             WhichButton initialButton,
  252.                             ODPlatformWindow theWindow,
  253.                             FW_PlatformEventTime when,
  254.                             const FW_CPoint& where,
  255.                             unsigned short modifiers,
  256.                             short numOfClicks) :
  257.     FW_CSystemEvent(ev, theWindow, when),
  258.     fFacet(theFacet),
  259.     fButtonState(theState),
  260.     fWhichButton(initialButton),
  261.     fNumberOfClicks(numOfClicks)
  262. {
  263. #ifdef FW_BUILD_MAC
  264.     if (theState == kMouseButtonDown)
  265.         fEvent.what = mouseDown;
  266.     else
  267.         fEvent.what = mouseUp;
  268.  
  269.     where.AsPlatformPoint(fEvent.where);
  270.     if (modifiers & kExtend)
  271.         fEvent.modifiers += shiftKey;
  272.     if (modifiers & kItem)
  273.         fEvent.modifiers += cmdKey;
  274.     if (modifiers & kCopy)
  275.         fEvent.modifiers += optionKey;
  276.     if (modifiers & kControl)
  277.         fEvent.modifiers += controlKey;
  278. #endif
  279.  
  280. #ifdef FW_BUILD_WIN
  281.     if (theState == kMouseButtonDown)
  282.     {
  283.         if (initialButton == kLeftMouseButton)
  284.             fEvent.message = WM_LBUTTONDOWN;
  285.         else if (initialButton == kMiddleMouseButton)
  286.             fEvent.message = WM_MBUTTONDOWN;
  287.         else
  288.             fEvent.message = WM_RBUTTONDOWN;
  289.     }
  290.     else
  291.     {
  292.         if (initialButton == kLeftMouseButton)
  293.             fEvent.message = WM_LBUTTONUP;
  294.         else if (initialButton == kMiddleMouseButton)
  295.             fEvent.message = WM_MBUTTONUP;
  296.         else
  297.             fEvent.message = WM_RBUTTONUP;
  298.     }
  299.     
  300.     where.AsPlatformPoint(fEvent.pt);
  301.     fEvent.lParam = fEvent.pt.y;
  302.     fEvent.lParam = fEvent.lParam << 16;
  303.     fEvent.lParam = fEvent.pt.x;
  304.  
  305.     if (modifiers & kExtend)
  306.         fEvent.wParam += MK_SHIFT;
  307.     if ((modifiers & kItem) || (modifiers & kCopy) || (modifiers & kControl))
  308.         fEvent.wParam += MK_CONTROL;
  309. #endif
  310. }
  311.  
  312. //----------------------------------------------------------------------------------------
  313. //    FW_CMouseEvent::FW_CMouseEvent
  314. //----------------------------------------------------------------------------------------
  315. FW_CMouseEvent::FW_CMouseEvent(Environment* ev, const FW_CEmbeddedMouseEvent& embeddedEvent) :
  316.     FW_CSystemEvent(ev, embeddedEvent)
  317. {
  318.     fFacet = embeddedEvent.GetFacet(ev);
  319.     fButtonState = embeddedEvent.GetButtonState(ev);
  320.     fWhichButton = embeddedEvent.GetInitialButtonPressed(ev);
  321.     fNumberOfClicks = embeddedEvent.GetNumberOfClicks(ev);
  322.  
  323. #ifdef FW_BUILD_MAC
  324.     if (fButtonState == kMouseButtonDown)
  325.         fEvent.what = mouseDown;
  326.     else
  327.         fEvent.what = mouseUp;
  328. #endif
  329.  
  330. #ifdef FW_BUILD_WIN
  331.     if (fButtonState == kMouseButtonDown)
  332.     {
  333.         if (fWhichButton == kLeftMouseButton)
  334.             fEvent.message = WM_LBUTTONDOWN;
  335.         else if (fWhichButton == kMiddleMouseButton)
  336.             fEvent.message = WM_MBUTTONDOWN;
  337.         else
  338.             fEvent.message = WM_RBUTTONDOWN;
  339.     }
  340.     else
  341.     {
  342.         if (fWhichButton == kLeftMouseButton)
  343.             fEvent.message = WM_LBUTTONUP;
  344.         else if (fWhichButton == kMiddleMouseButton)
  345.             fEvent.message = WM_MBUTTONUP;
  346.         else
  347.             fEvent.message = WM_RBUTTONUP;
  348.     }
  349. #endif
  350. }
  351.  
  352. //----------------------------------------------------------------------------------------
  353. //    FW_CMouseEvent::FW_CMouseEvent
  354. //----------------------------------------------------------------------------------------
  355. FW_CMouseEvent::FW_CMouseEvent(Environment* ev, const FW_CMouseEvent& other) :
  356.     FW_CSystemEvent(ev, other)
  357. {
  358.     fFacet = other.GetFacet(ev);
  359.     fButtonState = other.GetButtonState(ev);
  360.     fWhichButton = other.GetInitialButtonPressed(ev);
  361.     fNumberOfClicks = other.GetNumberOfClicks(ev);
  362. }
  363.  
  364. //----------------------------------------------------------------------------------------
  365. //    FW_CMouseEvent::~FW_CMouseEvent
  366. //----------------------------------------------------------------------------------------
  367. FW_CMouseEvent::~FW_CMouseEvent()
  368. {
  369. }
  370.  
  371. //----------------------------------------------------------------------------------------
  372. //    FW_CMouseEvent::GetButtonModifiers
  373. //----------------------------------------------------------------------------------------
  374. unsigned short FW_CMouseEvent::GetButtonModifiers(Environment* ev) const
  375. {
  376.     unsigned short modifiers = kEmpty;
  377.     
  378.     if (this->IsExtendModifier(ev))
  379.         modifiers |= kExtend;
  380.     if (this->IsItemModifier(ev))
  381.         modifiers |= kItem;
  382.     if (this->IsCopyModifier(ev))
  383.         modifiers |= kCopy;
  384.     if (this->IsControlKeyModifier(ev))
  385.         modifiers |= kControl;
  386.     
  387.     return modifiers;
  388. }
  389.  
  390. //----------------------------------------------------------------------------------------
  391. //    FW_CMouseEvent::GetLogicalMousePosition
  392. //----------------------------------------------------------------------------------------
  393.  
  394. FW_CPoint FW_CMouseEvent::GetLogicalMousePosition(Environment* ev, 
  395.                                             const FW_CMapping& mapping) const
  396. {
  397.     // [LSD] use kFrame for now: to fix later
  398.     FW_CPoint position = FW_CMouseEvent::GetMousePosition(ev, kFrame); 
  399.     
  400.     //     Note: I am calling DeviceToLogical and not LogicalToDevice because at this point position
  401.     //    is in "OpenDoc" coordinate (72 dpi on both platform) and I want it in logical coordinate
  402.     FW_SPlatformPoint plfmPoint = position;
  403.     mapping.DeviceToLogical(ev, plfmPoint, position, FW_CFacetPartInfo::GetFacetGraphicDevice(ev, fFacet), NULL);
  404.     
  405.     return position;
  406. }
  407.  
  408. //----------------------------------------------------------------------------------------
  409. //    FW_CMouseEvent::GetMousePosition
  410. //----------------------------------------------------------------------------------------
  411. // [LSD] This cannot return a position in Content coordinates because the ContentView may 
  412. // not be at the frame's origin.  Get Frame coordinates and convert to Content afterward.
  413.  
  414. FW_CPoint FW_CMouseEvent::GetMousePosition(Environment* ev, 
  415.                                             ECoordinates coordinate) const
  416. {
  417. #ifdef FW_BUILD_MAC
  418.         FW_SPlatformPoint mousePos(fEvent.where);
  419. #endif
  420. #ifdef FW_BUILD_WIN
  421.         FW_SPlatformPoint mousePos(fEvent.pt);
  422. #endif
  423.  
  424.     // ----- Convert into window coordinates -----
  425.     if (coordinate != kScreen)
  426.     {
  427. #ifdef FW_BUILD_MAC
  428.         ODWindow* aqWindow = fFacet->GetWindow(ev);        
  429.         GrafPtr svGrafPtr;
  430.         ::GetPort(&svGrafPtr);
  431.         GrafPtr grafPtr = aqWindow->GetPlatformWindow(ev);
  432.         ::SetPort(grafPtr);
  433.         FW_SPlatformPoint svOrigin(grafPtr->portRect.left, grafPtr->portRect.top);
  434.         ::SetOrigin(0,0);
  435.         ::GlobalToLocal(&mousePos);
  436.         ::SetOrigin(svOrigin.h, svOrigin.v);
  437.         ::SetPort(svGrafPtr);
  438. #endif
  439.  
  440. #ifdef FW_BUILD_WIN
  441.         // Use the global coordinate because the lParam field gets replaced if the event
  442.         // is an embedded mouse event
  443.         // !!! May need to worry about scrolling here
  444.         ::ScreenToClient((HWND)fEvent.hwnd, &mousePos);
  445.             // [WIN_PORT] fEvent.hwnd is a void* not an HWND!
  446. #endif
  447.     }
  448.     
  449.     FW_CPoint position = mousePos;
  450.     if (coordinate == kFrame) {
  451. #if FW_OPENDOC_VERSION >= FW_OPENDOC_DR3
  452.         FW_CAcquiredODTransform aqWindowFrameTransform = fFacet->AcquireWindowFrameTransform(ev, NULL);
  453. #else
  454.         FW_CAcquiredODTransform aqWindowFrameTransform = fFacet->GetWindowFrameTransform(ev, NULL);
  455. #endif
  456.         position.InverseTransform(ev, aqWindowFrameTransform);
  457.     }
  458.     
  459.     return position;
  460. }
  461.  
  462. //----------------------------------------------------------------------------------------
  463. //    FW_CMouseEvent::IsLeftButtonPressed
  464. //----------------------------------------------------------------------------------------
  465. FW_Boolean FW_CMouseEvent::IsLeftButtonPressed(Environment* ev) const
  466. {
  467. #ifdef FW_BUILD_MAC
  468.     return TRUE;
  469. #endif
  470. #ifdef FW_BUILD_WIN
  471.     return (fWhichButton == kLeftMouseButton) ? TRUE : (fEvent.wParam & MK_LBUTTON) != 0;
  472. #endif
  473. }
  474.  
  475. //----------------------------------------------------------------------------------------
  476. //    FW_CMouseEvent::IsMiddleButtonPressed
  477. //----------------------------------------------------------------------------------------
  478. FW_Boolean FW_CMouseEvent::IsMiddleButtonPressed(Environment* ev) const
  479. {
  480. #ifdef FW_BUILD_MAC
  481.     return FALSE;
  482. #endif
  483. #ifdef FW_BUILD_WIN
  484.     return (fWhichButton == kMiddleMouseButton) ? TRUE : (fEvent.wParam & MK_MBUTTON) != 0;
  485. #endif
  486. }
  487.  
  488. //----------------------------------------------------------------------------------------
  489. //    FW_CMouseEvent::IsRightButtonPressed
  490. //----------------------------------------------------------------------------------------
  491. FW_Boolean FW_CMouseEvent::IsRightButtonPressed(Environment* ev) const
  492. {
  493. #ifdef FW_BUILD_MAC
  494.     return FALSE;
  495. #endif
  496. #ifdef FW_BUILD_WIN
  497.     return (fWhichButton == kRightMouseButton) ? TRUE : (fEvent.wParam & MK_RBUTTON) != 0;
  498. #endif
  499. }
  500.  
  501. //----------------------------------------------------------------------------------------
  502. //    FW_CMouseEvent::IsExtendModifier
  503. //----------------------------------------------------------------------------------------
  504. FW_Boolean FW_CMouseEvent::IsExtendModifier(Environment* ev) const
  505. {
  506.     if (fButtonState != kMouseButtonDown)
  507.         return FALSE;
  508.     else
  509. #ifdef FW_BUILD_MAC
  510.         return (fEvent.modifiers & shiftKey) != 0;
  511. #endif
  512. #ifdef FW_BUILD_WIN
  513.         return (fEvent.wParam & MK_SHIFT) != 0;
  514. #endif
  515. }
  516.  
  517. //----------------------------------------------------------------------------------------
  518. //    FW_CMouseEvent::IsItemModifier
  519. //----------------------------------------------------------------------------------------
  520. FW_Boolean FW_CMouseEvent::IsItemModifier(Environment* ev) const
  521. {
  522.     if (fButtonState != kMouseButtonDown)
  523.         return FALSE;
  524.     else
  525. #ifdef FW_BUILD_MAC
  526.         return (fEvent.modifiers & cmdKey) != 0;
  527. #endif
  528. #ifdef FW_BUILD_WIN
  529.         return (fEvent.wParam & MK_CONTROL) != 0;
  530. #endif
  531. }
  532.  
  533. //----------------------------------------------------------------------------------------
  534. //    FW_CMouseEvent::WaitMouseMoved
  535. //----------------------------------------------------------------------------------------
  536. FW_Boolean FW_CMouseEvent::WaitUntilMouseMoved(Environment* ev) const
  537. {
  538. #ifdef FW_BUILD_MAC
  539.     return ::WaitMouseMoved(fEvent.where);
  540. #endif
  541. #ifdef FW_BUILD_WIN
  542.     MSG event;
  543.     BOOL bMoved = FALSE;
  544.     DWORD InitialTick = ::GetTickCount();
  545.     HWND hwnd = fFacet->GetWindow(ev)->GetPlatformWindow(ev);
  546.     /* Don't capture the mouse if we're minimized!
  547.      */
  548.     if(IsIconic(hwnd))
  549.         return FALSE;
  550.  
  551.     ::SetCapture(hwnd);
  552.     do
  553.     {
  554.         ::GetMessage(&event,NULL,NULL,NULL);
  555.         ::TranslateMessage(&event);    // Translates virtual key codes
  556.         ::DispatchMessage(&event);     // Dispatches message to window
  557.  
  558.         if (  (event.message == WM_LBUTTONUP)
  559.             || (event.message == WM_RBUTTONUP)
  560.             || (event.message == WM_LBUTTONDOWN)
  561.             || (event.message == WM_RBUTTONDOWN)
  562.             || (event.message == WM_CHAR)
  563.             || (::GetTickCount() < InitialTick)
  564.             || (::GetTickCount() > InitialTick+300)
  565.             )
  566.             break;
  567.         else if (event.message == WM_MOUSEMOVE)
  568.         {
  569.             int deltax = fEvent.pt.x - event.pt.x;
  570.             if (deltax<0) deltax *= -1;
  571.             int deltay = fEvent.pt.y - event.pt.y;
  572.             if (deltay<0) deltay *= -1;
  573.             bMoved = ((deltay >= 3) || (deltax >= 3));
  574.         }
  575.     } while(!bMoved);
  576.     ::ReleaseCapture();
  577.  
  578.     return  bMoved;
  579. #endif
  580.  
  581. }
  582.  
  583. //========================================================================================
  584. // CLASS FW_CEmbeddedMouseEvent
  585. //========================================================================================
  586.  
  587. //----------------------------------------------------------------------------------------
  588. //    FW_CEmbeddedMouseEvent::FW_CEmbeddedMouseEvent
  589. //----------------------------------------------------------------------------------------
  590. FW_CEmbeddedMouseEvent::FW_CEmbeddedMouseEvent(Environment* ev, ODEventData* theEvent,
  591.                                             ODFacet* theFacet,
  592.                                             ODFrame* theEmbeddedFrame,
  593.                                             ODFacet* theEmbeddedFacet,
  594.                                             ButtonState theState,
  595.                                             short numOfClicks) :
  596.     FW_CMouseEvent(ev, theEvent, theFacet, theState, numOfClicks),
  597.     fEmbeddedFrame(theEmbeddedFrame),
  598.     fEmbeddedFacet(theEmbeddedFacet)
  599. {
  600. }
  601.  
  602. //----------------------------------------------------------------------------------------
  603. //    FW_CEmbeddedMouseEvent::FW_CEmbeddedMouseEvent
  604. //----------------------------------------------------------------------------------------
  605. FW_CEmbeddedMouseEvent::FW_CEmbeddedMouseEvent(Environment* ev, ODFacet* theFacet,
  606.                                             ODFrame* theEmbeddedFrame,
  607.                                             ODFacet* theEmbeddedFacet,
  608.                                             ButtonState theState,
  609.                                             WhichButton initialButton,
  610.                                             ODPlatformWindow theWindow,
  611.                                             FW_PlatformEventTime when,
  612.                                             const FW_CPoint& where,
  613.                                             unsigned short modifiers,
  614.                                             short numOfClicks) :
  615.     FW_CMouseEvent(ev, theFacet, theState, initialButton, theWindow, when, where, modifiers, numOfClicks),
  616.     fEmbeddedFrame(theEmbeddedFrame),
  617.     fEmbeddedFacet(theEmbeddedFacet)
  618. {
  619. #ifdef FW_BUILD_MAC
  620.     if (theState == kMouseButtonDown)
  621.         fEvent.what = kODEvtMouseDownEmbedded;
  622.     else
  623.         fEvent.what = kODEvtMouseUpEmbedded;
  624. #endif
  625. #ifdef FW_BUILD_WIN
  626.     if (theState == kMouseButtonDown)
  627.         fEvent.message = kODEvtMouseDownEmbedded;
  628.     else
  629.         fEvent.message = kODEvtMouseUpEmbedded;
  630. #endif
  631. }
  632.  
  633. //----------------------------------------------------------------------------------------
  634. //    FW_CEmbeddedMouseEvent::FW_CEmbeddedMouseEvent
  635. //----------------------------------------------------------------------------------------
  636. FW_CEmbeddedMouseEvent::FW_CEmbeddedMouseEvent(Environment* ev, const FW_CEmbeddedMouseEvent& other) :
  637.     FW_CMouseEvent(ev, other)
  638. {
  639. }
  640.  
  641. //----------------------------------------------------------------------------------------
  642. //    FW_CEmbeddedMouseEvent::~FW_CEmbeddedMouseEvent
  643. //----------------------------------------------------------------------------------------
  644. FW_CEmbeddedMouseEvent::~FW_CEmbeddedMouseEvent()
  645. {
  646. }
  647.  
  648. //----------------------------------------------------------------------------------------
  649. //    FW_CEmbeddedMouseEvent::GetEmbeddedFrame
  650. //----------------------------------------------------------------------------------------
  651. ODFrame* FW_CEmbeddedMouseEvent::GetEmbeddedFrame(Environment* ev) const
  652. {
  653.     return fEmbeddedFrame;
  654. }
  655.  
  656. //----------------------------------------------------------------------------------------
  657. //    FW_CEmbeddedMouseEvent::GetEmbeddedFacet
  658. //----------------------------------------------------------------------------------------
  659. ODFacet* FW_CEmbeddedMouseEvent::GetEmbeddedFacet(Environment* ev) const
  660. {
  661.     return fEmbeddedFacet;
  662. }
  663.  
  664. //========================================================================================
  665. // CLASS FW_CBorderMouseEvent
  666. //========================================================================================
  667.  
  668. //----------------------------------------------------------------------------------------
  669. //    FW_CBorderMouseEvent::FW_CBorderMouseEvent
  670. //----------------------------------------------------------------------------------------
  671. FW_CBorderMouseEvent::FW_CBorderMouseEvent(Environment* ev, ODEventData* theEvent,
  672.                                             ODFacet* theFacet,
  673.                                             ODFrame* theEmbeddedFrame,
  674.                                             ODFacet* theEmbeddedFacet,
  675.                                             ButtonState theState,
  676.                                             short numOfClicks) :
  677.     FW_CMouseEvent(ev, theEvent, theFacet, theState, numOfClicks),
  678.     fEmbeddedFrame(theEmbeddedFrame),
  679.     fEmbeddedFacet(theEmbeddedFacet)
  680. {
  681. }
  682.  
  683. //----------------------------------------------------------------------------------------
  684. //    FW_CBorderMouseEvent::FW_CBorderMouseEvent
  685. //----------------------------------------------------------------------------------------
  686. FW_CBorderMouseEvent::FW_CBorderMouseEvent(Environment* ev, ODFacet* theFacet,
  687.                                             ODFrame* theEmbeddedFrame,
  688.                                             ODFacet* theEmbeddedFacet,
  689.                                             ButtonState theState,
  690.                                             WhichButton initialButton,
  691.                                             ODPlatformWindow theWindow,
  692.                                             FW_PlatformEventTime when,
  693.                                             const FW_CPoint& where,
  694.                                             unsigned short modifiers,
  695.                                             short numOfClicks) :
  696.     FW_CMouseEvent(ev, theFacet, theState, initialButton, theWindow, when, where, modifiers, numOfClicks),
  697.     fEmbeddedFrame(theEmbeddedFrame),
  698.     fEmbeddedFacet(theEmbeddedFacet)
  699. {
  700. #ifdef FW_BUILD_MAC
  701.     if (theState == kMouseButtonDown)
  702.         fEvent.what = kODEvtMouseDownBorder;
  703.     else
  704.         fEvent.what = kODEvtMouseUpBorder;
  705. #endif
  706. #ifdef FW_BUILD_WIN
  707.     if (theState == kMouseButtonDown)
  708.         fEvent.message = kODEvtMouseDownBorder;
  709.     else
  710.         fEvent.message = kODEvtMouseUpBorder;
  711. #endif
  712. }
  713.  
  714.  
  715. //----------------------------------------------------------------------------------------
  716. //    FW_CBorderMouseEvent::FW_CBorderMouseEvent
  717. //----------------------------------------------------------------------------------------
  718. FW_CBorderMouseEvent::FW_CBorderMouseEvent(Environment* ev, const FW_CBorderMouseEvent& other) :
  719.     FW_CMouseEvent(ev, other)
  720. {
  721. }
  722.  
  723. //----------------------------------------------------------------------------------------
  724. //    FW_CBorderMouseEvent::~FW_CBorderMouseEvent
  725. //----------------------------------------------------------------------------------------
  726. FW_CBorderMouseEvent::~FW_CBorderMouseEvent()
  727. {
  728. }
  729.  
  730. //----------------------------------------------------------------------------------------
  731. //    FW_CBorderMouseEvent::GetEmbeddedFrame
  732. //----------------------------------------------------------------------------------------
  733. ODFrame* FW_CBorderMouseEvent::GetEmbeddedFrame(Environment* ev) const
  734. {
  735.     return fEmbeddedFrame;
  736. }
  737.  
  738. //----------------------------------------------------------------------------------------
  739. //    FW_CBorderMouseEvent::GetEmbeddedFacet
  740. //----------------------------------------------------------------------------------------
  741. ODFacet* FW_CBorderMouseEvent::GetEmbeddedFacet(Environment* ev) const
  742. {
  743.     return fEmbeddedFacet;
  744. }
  745.  
  746.  
  747. //========================================================================================
  748. // CLASS FW_CVirtualKeyEvent
  749. //========================================================================================
  750.  
  751. //----------------------------------------------------------------------------------------
  752. //    FW_CVirtualKeyEvent::FW_CVirtualKeyEvent
  753. //----------------------------------------------------------------------------------------
  754. FW_CVirtualKeyEvent::FW_CVirtualKeyEvent(Environment* ev, 
  755.                                         ODEventData* theEvent,
  756.                                          KeyboardState theKeyboardState,
  757.                                          unsigned short repeatCount) :
  758.     FW_CSystemEvent(ev, theEvent),
  759.     fKeyboardState(theKeyboardState),
  760.     fRepeatCount(repeatCount)
  761. {
  762. }
  763.  
  764. //----------------------------------------------------------------------------------------
  765. //    FW_CVirtualKeyEvent::FW_CVirtualKeyEvent
  766. //----------------------------------------------------------------------------------------
  767. FW_CVirtualKeyEvent::FW_CVirtualKeyEvent(Environment* ev, 
  768.                                         KeyboardState theKeyboardState,
  769.                                         short keyCode,
  770.                                         ODPlatformWindow theWindow,
  771.                                         FW_PlatformEventTime when,
  772.                                         unsigned short repeatCount) :
  773.     FW_CSystemEvent(ev, theWindow, when),
  774.     fKeyboardState(theKeyboardState),
  775.     fRepeatCount(repeatCount)
  776. {
  777. #ifdef FW_BUILD_MAC
  778.     if (theKeyboardState == kKeyDown)
  779.     {
  780.         if (repeatCount > 0)
  781.             fEvent.what = autoKey;
  782.         else
  783.             fEvent.what = keyDown;
  784.     }
  785.     else
  786.         fEvent.what = keyUp;
  787.  
  788.     fEvent.message = keyCode << 8;
  789. #endif
  790.  
  791. #ifdef FW_BUILD_WIN
  792.     if (theKeyboardState == kKeyDown)
  793.             fEvent.message = WM_KEYDOWN;
  794.     else
  795.             fEvent.message = WM_KEYUP;
  796.  
  797.     fEvent.wParam = keyCode;
  798.     fEvent.lParam = repeatCount;
  799. #endif
  800. }
  801.  
  802. //----------------------------------------------------------------------------------------
  803. //    FW_CVirtualKeyEvent::FW_CVirtualKeyEvent
  804. //----------------------------------------------------------------------------------------
  805. FW_CVirtualKeyEvent::FW_CVirtualKeyEvent(Environment* ev, const FW_CVirtualKeyEvent& other) :
  806.     FW_CSystemEvent(ev, other)
  807. {
  808.     fKeyboardState = other.GetKeyboardState(ev);
  809.     fRepeatCount = other.GetRepeatCount(ev);
  810. }
  811.  
  812. //----------------------------------------------------------------------------------------
  813. //    FW_CVirtualKeyEvent::~FW_CVirtualKeyEvent
  814. //----------------------------------------------------------------------------------------
  815. FW_CVirtualKeyEvent::~FW_CVirtualKeyEvent()
  816. {
  817. }
  818.  
  819. //----------------------------------------------------------------------------------------
  820. //    FW_CVirtualKeyEvent::GetKeyCode
  821. //----------------------------------------------------------------------------------------
  822. short FW_CVirtualKeyEvent::GetKeyCode(Environment* ev) const
  823. {
  824. #ifdef FW_BUILD_MAC
  825.     return fEvent.message & keyCodeMask;
  826. #endif
  827. #ifdef FW_BUILD_WIN
  828.     return fEvent.wParam;
  829. #endif
  830. }
  831.  
  832. //========================================================================================
  833. // CLASS FW_CCharKeyEvent
  834. //========================================================================================
  835.  
  836. //----------------------------------------------------------------------------------------
  837. //    FW_CCharKeyEvent::FW_CCharKeyEvent
  838. //----------------------------------------------------------------------------------------
  839. FW_CCharKeyEvent::FW_CCharKeyEvent(Environment* ev, ODEventData* theEvent, unsigned short repeatCount) :
  840.     FW_CSystemEvent(ev, theEvent),
  841.     fRepeatCount(repeatCount)
  842. {
  843. }
  844.  
  845. //----------------------------------------------------------------------------------------
  846. //    FW_CCharKeyEvent::FW_CCharKeyEvent
  847. //----------------------------------------------------------------------------------------
  848. FW_CCharKeyEvent::FW_CCharKeyEvent(Environment* ev, 
  849.                                     char keyChar,
  850.                                     ODPlatformWindow theWindow,
  851.                                     FW_PlatformEventTime when,
  852.                                     unsigned short repeatCount) :
  853.     FW_CSystemEvent(ev, theWindow, when),
  854.     fRepeatCount(repeatCount)
  855. {
  856. #ifdef FW_BUILD_MAC
  857.     fEvent.what = keyDown;
  858.     fEvent.message = keyChar;
  859. #endif
  860.  
  861. #ifdef FW_BUILD_WIN
  862.     fEvent.message = WM_CHAR;
  863.     fEvent.wParam = keyChar;
  864.     fEvent.lParam = repeatCount;
  865. #endif
  866. }
  867.  
  868. //----------------------------------------------------------------------------------------
  869. //    FW_CCharKeyEvent::FW_CCharKeyEvent
  870. //----------------------------------------------------------------------------------------
  871. FW_CCharKeyEvent::FW_CCharKeyEvent(Environment* ev, const FW_CCharKeyEvent& other) :
  872.     FW_CSystemEvent(ev, other)
  873. {
  874.     fRepeatCount = other.GetRepeatCount(ev);
  875. }
  876.  
  877. //----------------------------------------------------------------------------------------
  878. //    FW_CCharKeyEvent::~FW_CCharKeyEvent
  879. //----------------------------------------------------------------------------------------
  880. FW_CCharKeyEvent::~FW_CCharKeyEvent()
  881. {
  882. }
  883.  
  884. //----------------------------------------------------------------------------------------
  885. //    FW_CCharKeyEvent::GetChar
  886. //----------------------------------------------------------------------------------------
  887. char FW_CCharKeyEvent::GetChar(Environment* ev) const
  888. {
  889. #ifdef FW_BUILD_MAC
  890.     return (char)fEvent.message & charCodeMask;
  891. #endif
  892. #ifdef FW_BUILD_WIN
  893.     return (char)fEvent.wParam;
  894. #endif
  895. }
  896.  
  897. //========================================================================================
  898. // CLASS FW_CActivateEvent
  899. //========================================================================================
  900.  
  901. //----------------------------------------------------------------------------------------
  902. //    FW_CActivateEvent::FW_CActivateEvent
  903. //----------------------------------------------------------------------------------------
  904. FW_CActivateEvent::FW_CActivateEvent(Environment* ev, ODEventData* theEvent, ODFacet* facet, FW_Boolean theState) :
  905.     FW_CSystemEvent(ev, theEvent),
  906.     fActivationState(theState),
  907.     fFacet(facet)
  908. {
  909. #ifdef FW_BUILD_MAC
  910.     fPlatformWindow = (ODPlatformWindow)fEvent.message;
  911. #endif
  912. #ifdef FW_BUILD_WIN
  913.     fPlatformWindow = (ODPlatformWindow)LOWORD(fEvent.lParam);
  914.         // [WIN_PORT] Messge param cracking for Win32/Win16 -- different!
  915. #endif
  916. }
  917.  
  918. //----------------------------------------------------------------------------------------
  919. //    FW_CActivateEvent::FW_CActivateEvent
  920. //----------------------------------------------------------------------------------------
  921. FW_CActivateEvent::FW_CActivateEvent(Environment* ev, ODFacet* facet,
  922.                                         FW_Boolean theState,
  923.                                         ODPlatformWindow theWindow,
  924.                                         FW_PlatformEventTime when) :
  925.     FW_CSystemEvent(ev, theWindow, when),
  926.     fActivationState(theState),
  927.     fFacet(facet)
  928. {
  929. #ifdef FW_BUILD_MAC
  930.     fEvent.what = activateEvt;
  931.     fEvent.message = (long)theWindow;
  932.     if (theState)
  933.         fEvent.modifiers = activeFlag;
  934. #endif
  935. #ifdef FW_BUILD_WIN
  936.     fEvent.message = WM_ACTIVATE;
  937.     if (theState)
  938.         fEvent.wParam = WA_ACTIVE;
  939.     else
  940.         fEvent.wParam = WA_INACTIVE;
  941.     fEvent.lParam = (LPARAM) theWindow;
  942. #endif
  943. }
  944.  
  945. //----------------------------------------------------------------------------------------
  946. //    FW_CActivateEvent::FW_CActivateEvent
  947. //----------------------------------------------------------------------------------------
  948. FW_CActivateEvent::FW_CActivateEvent(Environment* ev, const FW_CActivateEvent& other) :
  949.     FW_CSystemEvent(ev, other),
  950.     fActivationState(other.fActivationState),
  951.     fFacet(other.fFacet)
  952. {
  953. }
  954.  
  955. //----------------------------------------------------------------------------------------
  956. //    FW_CActivateEvent::~FW_CActivateEvent
  957. //----------------------------------------------------------------------------------------
  958. FW_CActivateEvent::~FW_CActivateEvent()
  959. {
  960. }
  961.  
  962. //========================================================================================
  963. // CLASS FW_CSuspendResumeEvent
  964. //========================================================================================
  965.  
  966. //----------------------------------------------------------------------------------------
  967. //    FW_CSuspendResumeEvent::FW_CSuspendResumeEvent
  968. //----------------------------------------------------------------------------------------
  969. FW_CSuspendResumeEvent::FW_CSuspendResumeEvent(Environment* ev, 
  970.                                                 ODEventData* theEvent, 
  971.                                                 ODFacet* facet, 
  972.                                                 FW_Boolean isGoingToBackground) :
  973.     FW_CSystemEvent(ev, theEvent),
  974.     fIsGoingToBackground(isGoingToBackground),
  975.     fFacet(facet)
  976. {
  977. }
  978.  
  979. //----------------------------------------------------------------------------------------
  980. //    FW_CSuspendResumeEvent::FW_CSuspendResumeEvent
  981. //----------------------------------------------------------------------------------------
  982. FW_CSuspendResumeEvent::FW_CSuspendResumeEvent(Environment* ev, const FW_CSuspendResumeEvent& other) :
  983.     FW_CSystemEvent(ev, other),
  984.     fIsGoingToBackground(other.fIsGoingToBackground)
  985. {
  986. }
  987.  
  988. //----------------------------------------------------------------------------------------
  989. //    FW_CSuspendResumeEvent::~FW_CSuspendResumeEvent
  990. //----------------------------------------------------------------------------------------
  991. FW_CSuspendResumeEvent::~FW_CSuspendResumeEvent()
  992. {
  993. }
  994.  
  995. //========================================================================================
  996. // CLASS FW_CMenuEvent
  997. //========================================================================================
  998.  
  999. //----------------------------------------------------------------------------------------
  1000. //    FW_CMenuEvent::FW_CMenuEvent
  1001. //----------------------------------------------------------------------------------------
  1002. FW_CMenuEvent::FW_CMenuEvent(Environment* ev, ODEventData* theEvent, ODCommandID theCommandID) :
  1003.     FW_CSystemEvent(ev, theEvent),
  1004.     fCommandID(theCommandID)
  1005. {
  1006. }
  1007.  
  1008. //----------------------------------------------------------------------------------------
  1009. //    FW_CMenuEvent::FW_CMenuEvent
  1010. //----------------------------------------------------------------------------------------
  1011. FW_CMenuEvent::FW_CMenuEvent(Environment* ev, 
  1012.                             ODCommandID theCommandID,
  1013.                             ODPlatformWindow theWindow,
  1014.                             FW_PlatformEventTime when) :
  1015.     FW_CSystemEvent(ev, theWindow, when),
  1016.     fCommandID(theCommandID)
  1017. {
  1018. #ifdef FW_BUILD_MAC
  1019.     fEvent.what = kODEvtMenu;
  1020.     fEvent.message = theCommandID;        // !!! this is wrong. should be menu item and id
  1021. #endif
  1022. #ifdef FW_BUILD_WIN
  1023.     fEvent.message = kODEvtMenu;
  1024.     fEvent.wParam = theCommandID;
  1025. #endif
  1026. }
  1027.  
  1028. //----------------------------------------------------------------------------------------
  1029. //    FW_CMenuEvent::FW_CMenuEvent
  1030. //----------------------------------------------------------------------------------------
  1031. FW_CMenuEvent::FW_CMenuEvent(Environment* ev, const FW_CMenuEvent& other) :
  1032.     FW_CSystemEvent(other)
  1033. {
  1034.     fCommandID = other.GetCommandID(ev);
  1035. }
  1036.  
  1037. //----------------------------------------------------------------------------------------
  1038. //    FW_CMenuEvent::~FW_CMenuEvent
  1039. //----------------------------------------------------------------------------------------
  1040. FW_CMenuEvent::~FW_CMenuEvent()
  1041. {
  1042. }
  1043.